package com.zhkj.txg.module.order.popup

import android.content.Context
import android.view.View
import android.view.animation.Animation
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.zhkj.txg.R
import com.zhkj.txg.module.order.adapter.ShippingCompanyAdapter
import com.zhkj.txg.module.order.entity.DeliveryEntity
import razerdp.basepopup.BasePopupWindow

class ShippingCompanyPopupWindow(context: Context, private val onSelect: (entity: DeliveryEntity) -> Unit) :
    BasePopupWindow(context) {

    private lateinit var adapter: ShippingCompanyAdapter


    override fun onCreateContentView(): View = createPopupById(R.layout.popup_refund_shipping)
    override fun onCreateShowAnimation(): Animation = getTranslateVerticalAnimation(1f, 0f, 300)
    override fun onCreateDismissAnimation(): Animation = getTranslateVerticalAnimation(0f, 1f, 300)

    override fun onViewCreated(contentView: View?) {
        contentView?.findViewById<View>(R.id.ivClose)?.setOnClickListener { dismiss() }
        contentView?.findViewById<RecyclerView>(R.id.rvShippingCompany)?.let { view ->
            view.layoutManager = LinearLayoutManager(context)
            adapter = ShippingCompanyAdapter { onSelect(it) }
            view.adapter = adapter
        }
    }

    fun setData(companyList: MutableList<DeliveryEntity>) {
        adapter.setNewData(companyList)
    }
}